package com.os.opencv.java.chapter7;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Size;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class Dilate {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        //读取图像并在屏幕上显示
        Mat src = Imgcodecs.imread("/Users/matt/Pictures/dog.jpg");
        HighGui.imshow("src", src);
        HighGui.waitKey(0);

        Mat dst = new Mat();

        //将图像反相编程黑底白字并在屏幕上显示
        Core.bitwise_not(src, src);
        HighGui.imshow("negative", src);
        HighGui.waitKey(0);

        //生成十字形结构元素
        Mat kernel = Imgproc.getStructuringElement(1, new Size(3,3));
        Point anchor = new Point(-1, -1);

        //膨胀1次并在屏幕上显示
        Imgproc.dilate(src, dst, new Mat());
        HighGui.imshow("dilate=1", dst);
        HighGui.waitKey(0);

        //膨胀3次并在屏幕上显示
        Imgproc.dilate(src, dst, kernel, anchor, 3);
        HighGui.imshow("dilate=3", dst);
        HighGui.waitKey(0);

        System.exit(0);
    }
}
